package com.ct.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

import com.ct.entity.po.Approval;
import com.ct.entity.po.Reimbursement;
import com.ct.entity.po.Schedule;
import com.ct.entity.query.ApprovalQuery;
import com.ct.entity.query.ReimbursementQuery;
import com.ct.entity.query.ScheduleQuery;
import com.ct.entity.vo.ApprovalStatusVO;
import com.ct.entity.vo.MapDataVO;
import com.ct.entity.vo.ReimbursementReportVO;
import com.ct.mappers.ReportMapper;
import com.ct.service.ReportService;
import com.ct.service.entity.ReportDataStrategy;
import com.ct.service.entity.ReportDataStrategyFactory;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;

/**
 * @Description:
 * @Author: cby
 * @Date: 2024/11/29 17:40
 */

@Service
public class ReportServiceImpl implements ReportService {
    @Resource
    ReportMapper<Reimbursement, ReimbursementQuery> reportReimbursementMapper;

    @Resource
    ReportMapper<Approval, ApprovalQuery> reportApprovalMapper;

    @Resource
    ReportMapper<Schedule, ScheduleQuery> reportScheduleMapper;

    private ReportDataStrategyFactory strategyFactory;

    @PostConstruct
    public void init() {
        strategyFactory = new ReportDataStrategyFactory(reportReimbursementMapper, reportApprovalMapper,
                reportScheduleMapper);
    }

    /**
     * 统计每个月份的经费总和
     * 
     * @param start 开始日期
     * @param end   结束日期
     * @return List<ReimbursementReportVO>
     */
    @Override
    public List<ReimbursementReportVO> getBarData(Date start, Date end) {
        ReportDataStrategy<List<ReimbursementReportVO>> strategy = strategyFactory.createStrategy("bar");
        return strategy.getData(start, end);
    }

    /**
     *
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @return 返回饼状图数据
     */
    @Override
    public ApprovalStatusVO getPieData(Date startDate, Date endDate) {
        ReportDataStrategy<ApprovalStatusVO> strategy = strategyFactory.createStrategy("pie");
        return strategy.getData(startDate, endDate);
    }

    /**
     *
     * @param startDate 开始时间
     * @param endDate   截止时间
     * @return 返回地图数据
     */
    @Override
    public List<MapDataVO> getMapData(Date startDate, Date endDate) {
        ReportDataStrategy<List<MapDataVO>> strategy = strategyFactory.createStrategy("map");
        return strategy.getData(startDate, endDate);
    }

}
